<template>
	<view class="w100 h100">
		<uni-card title="顾客信息" v-if="formData.is_save != 1">
			<uni-forms ref="form">
				<uni-forms-item label="联系人:" label-width="120">
					{{ formData.user_info.address ? formData.user_info.address.name :
					                        '' }}
				</uni-forms-item>
				<uni-forms-item label="手机号码:" label-width="120">
					{{ formData.user_info.address ? formData.user_info.address.mobile :
					                        '' }}
				</uni-forms-item>
				<uni-forms-item label="收货地址:" label-width="120">
					{{ formData.user_info.address ?
					                            formData.user_info.address.province + formData.user_info.address.city +
					                            formData.user_info.address.district + formData.user_info.address.full_address +
					                            formData.user_info.address.house_code
					                            : '' }}
				</uni-forms-item>
				<uni-forms-item label="用户备注:" label-width="120">
					{{ formData.remark }}
				</uni-forms-item>
			</uni-forms>
		</uni-card>
		<uni-card title="商品信息">
			<uni-forms ref="form">
				<uni-forms-item label="订单编号:" label-width="120">
					{{formData.order_no}}
				</uni-forms-item>
				<uni-forms-item label="结算单号:" label-width="120">
					{{formData.settle_no}}
				</uni-forms-item>
				<uni-forms-item label="购买时间:" label-width="120">
					{{formData.create_time}}
				</uni-forms-item>
				<uni-forms-item label="抖音订单编号:" label-width="120">
					{{formData.order_id}}
				</uni-forms-item>
				<uni-forms-item>
					<uni-card>
						<div class="card-header" style="font-weight: bold; font-size: 16px; color: brown">
							<span>
								{{ formData.product_name }}
							</span>
						</div>
						<div class="">
							<div v-for="(item, i) in formData.spec" :key="i">
								<div style="font-weight: 550">{{ item.tcname }}</div>
								<div v-for="(val, ii) in item.tclist" :key="ii" class="flex ml-4">
									<div>● {{ val.tcmingcname }}</div>
									<div>
										<span class="ml-10">({{ val.number }})</span>
										<span class="ml-4">￥{{ val.price }}</span>
									</div>
								</div>

							</div>
							<uni-card>
								<div style="font-weight: bold">商品价格：¥{{ formData.total_amount_info.product_price }}
								</div>
								<div style="font-weight: bold">包装费：¥{{ formData.total_amount_info.package_price }}
								</div>
								<div style="font-weight: bold">数量：{{ formData.total_amount_info.num }}</div>
							</uni-card>
						</div>
						<uni-card v-if="formData.add_data.length != 0">
							<div class="">
								<div v-for="(vv, i) in formData.add_data" :key="i">
									<div class="card-header" style="font-weight: bold; font-size: 16px; color: brown">
										<span>
											{{ vv.name }}
										</span>
									</div>
									<div class="flex ml-4">● {{ vv.item_data.name }}
										<div>
											<span class="ml-10">({{ vv.item_data.count }})</span>
											<span class="ml-4">¥{{ vv.item_data.add_price / 100 }}</span>
										</div>
									</div>
								</div>
							</div>
						</uni-card>
					</uni-card>
					<uni-card v-if="formData.other.length != 0">
						<div class="">
							<div v-for="(vv, i) in formData.other" :key="i">
								<div class="card-header" style="font-weight: bold; font-size: 16px; color: brown">
									<span>
										{{ vv.body }}
									</span>
								</div>
								<div v-for="(item, i) in vv.spec" :key="i">
									<div style="font-weight: 550">{{ item.tcname }}</div>
									<div v-for="(val, ii) in item.tclist" :key="ii" class="flex ml-4">
										<div>● {{ val.tcmingcname }}</div>
										<div>
											<span class="ml-10">({{ val.number }})</span>
											<span class="ml-4">¥{{ val.price }}</span>
										</div>
									</div>
								</div>

								<uni-card v-if="vv.add_data">
									<div v-for="(vv, i) in vv.add_data" :key="i">
										<div style="font-weight: 550">{{ vv.name }}</div>
										<div class="flex ml-4">● {{ vv.item_data.name }}
											<div>
												<span class="ml-10">({{ vv.item_data.count }})</span>
												<span class="ml-4">¥{{ vv.item_data.add_price / 100 }}</span>
											</div>
										</div>
									</div>
								</uni-card>

								<uni-card>
									<div style="font-weight: bold">商品价格：¥{{ vv.total_amount_info.product_price
					                                                }}</div>
									<div style="font-weight: bold">包装费：¥{{ vv.total_amount_info.package_price }}
									</div>
									<div style="font-weight: bold">数量：{{ vv.total_amount_info.num }}</div>
								</uni-card>
							</div>
						</div>
					</uni-card>
				</uni-forms-item>
			</uni-forms>
		</uni-card>
		<uni-card title="先囤单信息" v-if="formData.xiantunobj">
			<uni-forms ref="form">
				<uni-forms-item label="先囤订单编号:" label-width="120">
					{{formData.xiantunobj.order_no}}
				</uni-forms-item>
				<uni-forms-item label="先囤抖音订单编号:" label-width="120">
					{{formData.xiantunobj.order_id}}
				</uni-forms-item>
				<uni-forms-item label="先囤支付金额:" label-width="120">
					￥{{formData.xiantunobj.dy_total_amount / 100}}
				</uni-forms-item>
				<uni-forms-item label="先囤结算单号:" label-width="120">
					<span v-if="this.formData.xiantunobj.settle_no != null">{{formData.xiantunobj.settle_no}}</span>
					<span v-else>-</span>
				</uni-forms-item>
				<uni-forms-item label="先囤订单类型:" label-width="120">
					<text v-if="formData.xiantunobj.other.length == 0">外卖单</text>
					<text v-if="formData.xiantunobj.other.length != 0">购物车</text>
				</uni-forms-item>
				<uni-forms-item label="先囤购买时间:" label-width="120">
					{{formData.xiantunobj.user_info.create_time}}
				</uni-forms-item>
			</uni-forms>
		</uni-card>
		<uni-card title="后约单信息" v-if="formData.houyueobj">
			<uni-forms ref="form">
				<uni-forms-item label="后约订单编号:" label-width="120">
					{{formData.houyueobj.order_no}}
				</uni-forms-item>
				<uni-forms-item label="后约抖音订单编号:" label-width="120">
					{{formData.houyueobj.order_id}}
				</uni-forms-item>
				<uni-forms-item label="后约支付金额:" label-width="120">
					￥{{formData.houyueobj.dy_total_amount / 100}}
				</uni-forms-item>
				<uni-forms-item label="后约结算单号:" label-width="120">
					<span v-if="this.formData.houyueobj.settle_no != null">{{formData.houyueobj.settle_no}}</span>
					<span v-else>-</span>
				</uni-forms-item>
				<uni-forms-item label="后约订单类型:" label-width="120">
					<text v-if="formData.houyueobj.other.length == 0">外卖单</text>
					<text v-if="formData.houyueobj.other.length != 0">购物车</text>
				</uni-forms-item>
				<uni-forms-item label="后约购买时间:" label-width="120">
					{{formData.houyueobj.user_info.create_time}}
				</uni-forms-item>
			</uni-forms>
		</uni-card>
		<uni-card title="配送信息">
			<uni-forms ref="form">
				<uni-forms-item label="下单门店:" label-width="120">
					{{ formData.store_name }}
				</uni-forms-item>
				<uni-forms-item label="配送方式:" label-width="120" v-if="formData.is_save != 1">
					{{ formData.rider_info ? formData.rider_info.logistic_tag : '' }}
				</uni-forms-item>
				<uni-forms-item label="预约时间:" label-width="120" v-if="formData.is_save != 1">
					{{ formData.delivery_time }}
				</uni-forms-item>
				<uni-forms-item label="送达时间:" label-width="120" v-if="formData.is_save != 1">
					{{ formData.rider_info ? formData.delivery_end_time : '' }}
				</uni-forms-item>
				<uni-forms-item label="退款申请时间:" label-width="120">
					{{ formData.return_apply_time }}
				</uni-forms-item>
				<uni-forms-item label="退款原因:" label-width="120">
					{{ formData.return_apply_msg }}
				</uni-forms-item>
				<uni-forms-item label="退款同意时间:" label-width="120">
					{{ formData.return_time }}
				</uni-forms-item>
				<uni-forms-item label="抖音退款单号:" label-width="120">
					{{ formData.dy_refund_no }}
				</uni-forms-item>
				<uni-forms-item label="抖音退款时间:" label-width="120">
					{{ formData.dy_return_time }}
				</uni-forms-item>
				<uni-forms-item label="抖音退款失败原因:" label-width="150">
					{{ formData.dy_return_error_text }}
				</uni-forms-item>
				<uni-forms-item label="抖音是否为分账后退款:" label-width="150">
					{{ formData.dy_is_all_settled }}
				</uni-forms-item>
			</uni-forms>
		</uni-card>
		<uni-card title="收支明细">
			<uni-forms ref="form">
				<uni-forms-item label="商家预计收入:" label-width="120">
					<view class="bega">总计：¥{{ formData.store_price / 100 }}</view>
				</uni-forms-item>
				<uni-forms-item label="软件服务费:" label-width="120">
					¥{{ formData.dy_price / 100 }}
				</uni-forms-item>
				<uni-forms-item label="达人佣金:" label-width="120">
					{{ formData.cps_price / 100 }}
				</uni-forms-item>
				<uni-forms-item label="服务商佣金:" label-width="120">
					<div class="conmsg">{{ formData.agent_price / 100 }}(比例：{{ formData.agent_ratio
					                                        }}%) +{{ formData.oem_price / 100 }}(比例：{{ formData.oem_ratio }}%)</div>
				</uni-forms-item>
				<uni-forms-item label="代理商佣金:" label-width="120">
					{{ formData.partner_price / 100 }}(比例：{{
					                                        formData.partner_ratio }}%)
				</uni-forms-item>
				<uni-forms-item label="用户实际支付:" label-width="120">
					<view class="bega">总计：<span class="jia">¥{{ formData.dy_total_amount / 100 }}</span></view>
				</uni-forms-item>
				<uni-forms-item label="商品金额:" label-width="120">
					<div class="conmsg" v-if="formData.other.length == 0">¥{{
					                                        formData.total_amount_info.product_price }}</div>
					<div class="conmsg" v-if="formData.other.length != 0">¥{{ formData.product_price }}
					</div>
				</uni-forms-item>
				<uni-forms-item label="顾客应付配送费:" label-width="120">
					¥{{ formData.total_amount_info.delivery_price }}
				</uni-forms-item>
				<uni-forms-item label="顾客应付包装费:" label-width="120">
					¥{{ formData.total_amount_info.package_price }}
				</uni-forms-item>
				<uni-forms-item label="商家商品补贴:" label-width="150">
					-
				</uni-forms-item>
				<uni-forms-item label="平台商品补贴:" label-width="150">
					-
				</uni-forms-item>
			</uni-forms>
		</uni-card>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderId: 0,
				formData: {},
				val: {}
			};
		},
		onLoad(option) {
			const val = JSON.parse(decodeURIComponent(option.item))
			if (val.is_save == 2) {
				this.beg.request({
					url: '/admin/order.Order/get_main_order_data',
					method: "post",
					data: {
						main_id: val.main_id
					}
				}).then((res) => {
					if (res.code == 1) {
						val.xiantunobj = res.data
						this.formData = val
						this.formData.spec = JSON.parse(this.formData.spec)
						this.formData.total_amount_info = JSON.parse(this.formData.total_amount_info)
						this.formData.rider_info = JSON.parse(this.formData.rider_info)
						this.null2str(this.formData)
					}
				})
			} else if (val.is_save == 1) {
				const main_id = val.id;
				this.beg.request({
					url: '/admin/order.Order/get_other_order_data',
					method: "post",
					data: {
						main_id: main_id
					}
				}).then((res) => {
					if (res.code == 1) {
						val.houyueobj = res.data
						this.formData = val
						this.formData.spec = JSON.parse(this.formData.spec)
						this.formData.total_amount_info = JSON.parse(this.formData.total_amount_info)
						this.formData.rider_info = JSON.parse(this.formData.rider_info)
						this.null2str(this.formData)
					}
				})
			} else {
				if (val.add_data) {
					val.add_data = JSON.parse(val.add_data)
					val.other.forEach((v) => {
						if (v.add_data) {
							v.add_data = JSON.parse(v.add_data)
						}
					})
				}
				if (val.other) {
					val.other.forEach((v) => {
						if (v.total_amount_info) {
							v.total_amount_info = JSON.parse(v.total_amount_info)
						}
						if(v.spec){
							v.spec = JSON.parse(v.spec)
						}
						if(v.add_data){
							v.add_data = JSON.parse(v.add_data)
						}
					})
				}
				this.formData = val
				this.formData.spec = JSON.parse(this.formData.spec)
				this.formData.total_amount_info = JSON.parse(this.formData.total_amount_info)
				this.formData.rider_info = JSON.parse(this.formData.rider_info)
				this.null2str(this.formData)
				console.log(this.formData);
			}
		},
		methods: {
			null2str(data) {
				for (let x in data) {
					if (data[x] === null) {
						data[x] = "";
					}
				}
				return data;
			},
		}
	}
</script>

<style lang="scss">
	::v-deep .uni-forms-item {
		align-items: center;
	}

	.bega {
		background-color: #dfe4ec;
		display: flex;
		justify-content: center;
		font-weight: 700;
	}
</style>